#include "stdio.h"
#include "string.h"
#include<iostream>
using namespace std;

int main(){
	
	int a0;
	int a1;
	int r,s;
	int k;
	int result;
	while( scanf("%d%d%d%d%d",&a0,&a1,&r,&s,&k) ){//cin>>a0>>a1>>r>>s>>k)
	
	if(k==0) {printf("%d\n",a0);continue;}
	if(k==1) {printf("%d\n",a1);continue;}
	while(k>1){
		k--;
		result = a1*r + a0*s;
		a0 = a1;
		a1 = result%10000;
	}
	printf("%d\n",a1);
    }
    //	system("pause");
	return 0;

}

